package io.web.usercenter.utils;

import com.github.pagehelper.PageInfo;
import lombok.Builder;
import lombok.Data;

import java.util.List;

/**
 * PageWrapper.
 *
 * @date 2023-05-15
 */
public class PageWrapper {

    public static <T> PageResponse<T> pageWrapper(List<T> source) {
        PageInfo<T> res = PageInfo.of(source);
        List<T> target = res.getList();
        return PageResponse.<T>builder()
                .data(target)
                .pageNo(res.getPageNum())
                .pageSize(res.getPageSize())
                .totalCount(res.getTotal())
                .totalPage(res.getPages())
                .build();
    }

    @Data
    @Builder
    public static class PageResponse<E> {
        private List<E> data;
        private Integer pageSize;
        private Integer pageNo;
        private Integer totalPage;
        private Long totalCount;
    }
}
